import { NavigationActions } from 'react-navigation';
import { routerReducer } from '../router';

const actions = [
  NavigationActions.BACK,
  NavigationActions.INIT,
  NavigationActions.NAVIGATE,
  NavigationActions.RESET,
  NavigationActions.SET_PARAMS,
  NavigationActions.URI,
];

export default {
  namespace: 'router',
  state: {
    ...routerReducer(),
  },
  reducers: {
    apply(state, { payload: action }) {
      // console.log(routerReducer(state, action), 'routerReducer(state, action)routerReducer(state, action)routerReducer(state, action)');
      return routerReducer(state, action);
    },
  },
  effects: {
    watch: [
      function* watch({ take, call, put }) {
        const loop = true;
        while (loop) {
          const payload = yield take(actions);
          // console.log('---------gogoggo');
          // console.log('--watchwatchwatchwatch----');
          yield put({
            type: 'apply',
            payload,
          });
          // if (payload.type === 'Navigation/NAVIGATE') {
          //   yield call(delay, 250)
          // }
        }
      },
      { type: 'watcher' },
    ],
  },
};
